home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / demos / cpitdemo / cpit_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-10  |  4.6 KB  |  198 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)cpit_main.c    V1.7    3/15/95";
  3. #endif
  4.  
  5. /*------------------------------------------------------------------
  6. | file name -- cpit_main.c
  7. |-----------------------------------------------------------------*/
  8.  
  9. #include "std.h"
  10. #include "dvstd.h"
  11. #include "dvtools.h"
  12. #include "Tfundecl.h"
  13. #include "VOfundecl.h"
  14. #include "VUerfundecl.h"
  15. #include "GRfundecl.h"
  16. #include "cpit_vars.h"
  17. #include "cpit_fundecl.h"
  18. #include "MISCfuns.h"
  19.  
  20. #ifdef WINNT
  21. #include <windows.h>
  22. #endif /* WINNT */
  23.  
  24.  
  25. #ifndef WINNT 
  26.  
  27. /* Include the X based files so we can add AppTimeOuts */
  28. #ifdef CONST
  29. #undef CONST
  30. #endif
  31.  
  32. #ifndef __STDC__
  33. #define _NO_PROTO
  34. #endif
  35.  
  36. /* X11 include files */
  37. #include <X11/Xlib.h>
  38. #include <X11/Intrinsic.h>
  39.  
  40. #endif /* Not WINNT */
  41.  
  42.  
  43. /* This program can be linked to run:
  44. |
  45. |  With 100% CPU usage (which shows updates in a tight loop)
  46. |    comment #define DV_USE_TIMER
  47. |  With Time-Outs (which show update based on a timer).
  48. |    uncomment #define DV_USE_TIMER
  49. */
  50. #define DV_USE_TIMER
  51.  
  52. #ifdef DV_USE_TIMER
  53.  
  54. LOCAL INT TimeoutInterval = 10;
  55.  
  56. #ifdef WINNT
  57.  
  58. LOCAL HWND Hwnd;
  59. LOCAL VOID CALLBACK TimeOutProc V_P_((HWND hwnd,
  60.                                       UINT uMsg,
  61.                                       UINT idEvent,
  62.                                       DWORD dwTime));
  63.  
  64. #else /* UNIX */
  65.  
  66. LOCAL XtAppContext app_context;
  67. LOCAL  void UpdateProc V_P_((ADDRESS args, XtIntervalId *interval_id));
  68.  
  69. #endif /* WINNT */
  70. #endif /* DV_USE_TIMER */
  71.  
  72.  
  73.  
  74.  
  75. #define SEARCH_PATH     (CHAR*)NULL
  76. #define DISPFORM_TABLE  (CHAR*)NULL
  77.  
  78.  
  79. /*--------------------------------------------------------------------
  80. |  main()
  81. |    This module is the basic skeleton of a DataViews application.
  82. |
  83. */
  84.  
  85. #ifdef WINNT 
  86. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  87.                      LPSTR lpCmdLine,  int nCmdShow  )
  88. {
  89.     CHAR *device = NULL;
  90.     INT argc;
  91.     CHAR **argv;
  92.  
  93.     make_argv(&argc,&argv,GetCommandLine());
  94.  
  95. #else  /* Not WINNT */
  96. int 
  97. main (argc, argv)
  98.      int argc;
  99.      char *argv[];
  100. {
  101.   CHAR *device = NULL;
  102.  
  103. #endif /* WINNT */
  104.  
  105.  
  106.   /* Initialize arguments, argv[1] - device name */
  107.   if (argc > 1)
  108.     device = argv[1];
  109.  
  110.   /* Initialize */
  111.   /* DataViews Initializaton */
  112.   (VOID) TInit (SEARCH_PATH, DISPFORM_TABLE);
  113.  
  114.   InitDisplays (device);        /* found in cpit_dsp.c */
  115.  
  116. #ifdef DV_USE_TIMER
  117. #ifdef WINNT
  118.     /* Get the Windows based information */
  119.     (VOID) GRget (V_WIN32_WINDOW_HANDLE, &Hwnd, V_END_OF_LIST);
  120.     
  121.  /* Post a timeout for dynamic updates
  122.   |  The timeout procedure will update the dynamics of
  123.   |  all screens which have been opened. The procedure is invoked
  124.   |  whenever the specified time interval elapses. The interval is
  125.   |  specified in milliseconds.
  126.   */
  127.     SetTimer (Hwnd, (UINT)Hwnd, TimeoutInterval, (TIMERPROC)TimeOutProc);
  128. #else
  129.  /* Extract the X information so we can setup a Time-Out Proc
  130.  |  for updating....
  131.  |     Get the Xt Application Context information.
  132.  |     Post a timeout procedure will update the dynamics of
  133.  |     all screens which have been opened. The procedure is invoked
  134.  |     whenever the specified time interval elapses. The interval is
  135.  |     specified in milliseconds.
  136.  */
  137.   (VOID) GRget (V_X_APPLIC_CONTEXT, &app_context, V_END_OF_LIST);
  138.   XtAppAddTimeOut (app_context, TimeoutInterval, 
  139.            (XtTimerCallbackProc) UpdateProc, NULL);
  140.  
  141. #endif /*  WINNT */
  142. #endif /* DV_USE_TIMER */
  143.  
  144.  
  145.   /* Control Loop */
  146.   ApplicationState = (DV_BOOL) RUNNING;
  147.   while (ApplicationState == RUNNING)
  148.     {
  149.       /* Gather and Process User Inputs
  150.       |    Note: since we posted a time-out, the event
  151.       |    handler will call our function to handle
  152.       |    the updating of dynamic objects.
  153.       */
  154.  
  155.       /* Gather and Process User Inputs */
  156.       HandleEvents ();          /* found in cpit_event.c */
  157.  
  158.     }
  159.  
  160.   /* Termination and Clean Up */
  161.   TermDisplays ();              /* found in cpit_dsp.c */
  162.  
  163.   (VOID) TTerminate ();         /* DataViews Termination */
  164.   return 1;
  165. }
  166.  
  167. #ifdef DV_USE_TIMER
  168. #ifdef WINNT
  169.  
  170. /*ARGSUSED*/
  171. LOCAL VOID CALLBACK
  172. TimeOutProc (hwnd, uMsg, idEvent, dwTime)
  173.     HWND hwnd;
  174.   UINT uMsg;
  175.     UINT idEvent;
  176.     DWORD dwTime;
  177. {
  178.     HandleDynamics ();
  179. }
  180.  
  181. #else
  182. /*ARGSUSED*/
  183. LOCAL void 
  184. UpdateProc (args, interval_id)
  185.      ADDRESS args;
  186.      XtIntervalId *interval_id;
  187. {
  188.  
  189.   /* Update the current View */
  190.   HandleDynamics ();
  191.  
  192.   /* Re-Post the Time-Out */
  193.   XtAppAddTimeOut (app_context, TimeoutInterval, 
  194.            (XtTimerCallbackProc) UpdateProc, NULL);
  195. }
  196. #endif  /* WINNT */
  197. #endif /* DV_USE_TIMER */
  198.